package com.example.Activity.service.impl;

import com.example.Activity.domain.ActivityRegistration;
import com.example.Activity.domain.Bo.ActivityRegistrationAddBo;
import com.example.Activity.domain.Vo.ActivityRegistrationListVo;
import com.example.Activity.mapper.ActivityRegistrationMapper;
import com.example.Activity.service.IActivityRegistrationService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityRegistrationServiceImpl implements IActivityRegistrationService {

    @Autowired
    private ActivityRegistrationMapper activityRegistrationMapper;

    @Override
    public List<ActivityRegistrationListVo> selectActivityRegistration(ActivityRegistrationAddBo registrationBo) {
        ActivityRegistration registration = new ActivityRegistration();
        BeanUtils.copyProperties(registrationBo, registration);
        return activityRegistrationMapper.selectActivityRegistration(registration);
    }

    @Override
    public void insertActivityRegistration(ActivityRegistrationAddBo registrationBo) {
        ActivityRegistration registration = new ActivityRegistration();
        BeanUtils.copyProperties(registrationBo, registration);
        registration.setCreateTime(LocalDateTime.now());
        registration.setUpdateTime(LocalDateTime.now());
        activityRegistrationMapper.insertActivityRegistration(registration);
    }

    @Override
    public void updateActivityRegistrationById(ActivityRegistrationAddBo registrationBo) {
        ActivityRegistration registration = new ActivityRegistration();
        BeanUtils.copyProperties(registrationBo, registration);
        registration.setUpdateTime(LocalDateTime.now());
        activityRegistrationMapper.updateActivityRegistrationById(registration);
    }

    @Override
    public void deleteActivityRegistrationById(String id) {
        activityRegistrationMapper.deleteActivityRegistrationById(id);
    }

    @Override
    public ActivityRegistrationListVo selectActivityRegistrationById(Integer id) {
        ActivityRegistration registration = new ActivityRegistration();
        registration.setId(id);
        List<ActivityRegistrationListVo> list = activityRegistrationMapper.selectActivityRegistration(registration);
        return list != null && !list.isEmpty() ? list.get(0) : null;
    }
}